﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WebSite.Core;
using Common;

namespace WebSite
{
    public partial class ViewBaby : BasePage
    {
        public int currentTeamID = 0;
        public Maticsoft.Model.CarrefourCover.Baby babyA = null;
        public string babyAHeadImage = null;
        public string babyBHeadImage = null;
        public string babyALiveImage1 = null;
        public string babyALiveImage2 = null;
        public string babyBLiveImage1 = null;
        public string babyBLiveImage2 = null;
        public Maticsoft.Model.CarrefourCover.Baby babyB = null;
        
        public Maticsoft.Model.CarrefourCover.Team curTeam = null;

        protected void Page_Load( object sender, EventArgs e )
        {
            Maticsoft.BLL.CarrefourCover.Team teambll = new Maticsoft.BLL.CarrefourCover.Team();
            Maticsoft.BLL.CarrefourCover.Baby babybll = new Maticsoft.BLL.CarrefourCover.Baby();
            
            NavHelper.SetNavMenuSelectedIndex( 1 );
            NavHelper.SetNavStepCurrentStep( 0 );

            int babyid = StringHelper.Convert(Request["babyid"], 0);

            babyA = babybll.GetModel(babyid);
            if (babyA == null)
            {
                AlertMessage( "参数错误", "/index.aspx" );
            }

            //int curTeamID = NullableHelper.CastValueType( Project_Session.CurrentUserBaby.ConfirmTeamId );
            //if ( curTeamID == 0)
            //{
            //    babyA = Project_Session.CurrentUserBaby;
            //}
            //else
            //{
            //    curTeam = teambll.GetModel( curTeamID );
            //    if (curTeam == null)
            //    {
            //        babyA = Project_Session.CurrentUserBaby;
            //    }
            //    else
            //    {
            //        babyA = babybll.GetModel( curTeam.BabyAId.Value );
            //        babyB = babybll.GetModel( curTeam.BabyBId.Value );

            //        NavHelper.SetNavStepCurrentStep( 4 );
            //    }
            //}
            
            // 获取生活照
            Maticsoft.BLL.CarrefourCover.Image imgbll = new Maticsoft.BLL.CarrefourCover.Image();
            babyAHeadImage = babyBHeadImage = babyALiveImage1 = babyALiveImage2 = 
                babyBLiveImage1 = babyBLiveImage2 = "/images/BabyGroup/waitselect_200.png";

            if (babyA != null)
            {
                babyAHeadImage = babyA.BabyHeadImg;
                var liveImageA = imgbll.GetLiveImageByBabyID( babyA.Id );

                if (liveImageA.Count > 0)
                {
                    babyALiveImage1 = liveImageA[0].ImgUrl;
                }
                if (liveImageA.Count > 1)
                {
                    babyALiveImage2 = liveImageA[1].ImgUrl;
                }
            }

            if (babyB != null)
            {
                babyBHeadImage = babyB.BabyHeadImg;
                var liveImageB = imgbll.GetLiveImageByBabyID( babyB.Id );

                if (liveImageB.Count > 0)
                {
                    babyBLiveImage1 = liveImageB[0].ImgUrl;
                }
                if (liveImageB.Count > 1)
                {
                    babyBLiveImage2 = liveImageB[1].ImgUrl;
                }
            }
        }
    }
}